import { md5 } from 'js-md5'
import { postService } from '.'
import { PORT1 } from '../config/net.config'
import { User } from './interface/user'
import { loginRSA } from '/@/config'
import request from '/@/utils/request'

interface FormType {
  password: string
  password2?: string
  phone: string
  phoneCode: string
  username: string
  verificationCode: string
}

export const login = async (data: any) => {
  if (loginRSA) data = { ...data, password: md5(data.password) }
  return request({
    url: `${PORT1}/Login/GetJwtToken`,
    method: 'post',
    data,
  })
}
export const getIdentify = async (data: any) => {
  return request({
    url: `${PORT1}/Login/GetIdentify`,
    method: 'post',
    data,
    headers: {
      // 'Content-Type': 'multipart/form-data',
    },
  })
}
export const getNavs = async (data: any) => {
  return postService(`${PORT1}/SysMenuPage/GetPageList`, data, 'form')
}
export const getButtons = async (data: any) => {
  return request({
    url: `${PORT1}/SysMenuPageDict/GetPageList`,
    method: 'post',
    data,
  })
}

export const getUserInfo = (params: {}) => {
  return postService<User.UserInfo>(`${PORT1}/Tools/GetEditUserInfo`, params, 'json')
}

export const editUserInfoAPI = (params: User.UserInfo) => {
  return postService<null>(`${PORT1}/Tools/EditLoginUserInfo`, params, 'json')
}
export const changePasswordAPI = (params: User.ChangePriceForm) => {
  return postService<null>(`${PORT1}/SysUser/ChangePassWord`, params, 'form')
}

export const logout = () => {
  return request({
    url: '/logout',
    method: 'get',
  })
}

export const register = (data: FormType) => {
  return request({
    url: '/register',
    method: 'post',
    data,
  })
}

export const password = (data: FormType) => {
  return request({
    url: '/password',
    method: 'post',
    data,
  })
}

export const lock = () => {
  return request({
    url: '/lock',
    method: 'get',
  })
}
